//
//  ScanStockViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15/8/10.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "ScanStockViewController.h"
#import "ScanStockTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface ScanStockViewController ()
{
    NSInteger typeTag;
    
    NSString *typeNameStr;
    
//    NSMutableArray *rightCodeArray;
//    NSMutableArray *inventoryRightCodeArray;
    
    NSString *rightCodeStr;
    NSString *guideCodeStr;
    
    NSString *inventoryRightCodeStr;
    
    NSString *whereTypeStr;
    
    BOOL scrollIsOpen;
    NSMutableArray *itemCodeArray;
    NSMutableArray *itemNameArray;
    NSMutableArray *itemWhereArray;
    NSMutableArray *itemPriceArray;
     NSMutableArray *itemUrlArray;
    NSMutableArray *itemWeightArray;
    
    NSMutableArray *itemNotExitArray;

}

@end

@implementation ScanStockViewController

-(void)viewWillAppear:(BOOL)animated
{
    _clearAllBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _clearAllBtn.layer.borderWidth= 1.0f;
    _clearAllBtn.layer.cornerRadius=3;
    [_clearAllBtn addTarget:self action:@selector(clearAllBtnClick) forControlEvents:UIControlEventTouchUpInside];
   
    
    whereTypeStr=@"";
    
    scrollIsOpen=NO;
    
    [self initPopView];
    [self initPopResultView];
    [self initScanResult];
    
    UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap)];
    [self.view addGestureRecognizer:singleTap];
   // NSLog(@"22222===%@",_itemCodeArray);
   
    
    
}
-(void)initScanResult
{
   
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    if ([userDefaults objectForKey:@"SCANSTOCKITEMCODE"]) {
        itemCodeArray=[NSMutableArray arrayWithArray:[userDefaults objectForKey:@"SCANSTOCKITEMCODE"]];
        itemNameArray=[NSMutableArray arrayWithArray:[userDefaults objectForKey:@"SCANSTOCKITEMNAME"]];
        itemWhereArray=[NSMutableArray arrayWithArray:[userDefaults objectForKey:@"SCANSTOCKITEMWHERE"]];
        itemPriceArray=[NSMutableArray arrayWithArray:[userDefaults objectForKey:@"SCANSTOCKITEMPRICE"]];
        itemUrlArray=[NSMutableArray arrayWithArray:[userDefaults objectForKey:@"SCANSTOCKITEMURL"]];
        itemWeightArray=[NSMutableArray arrayWithArray:[userDefaults objectForKey:@"SCANSTOCKITEMWEIGHT"]];
        
      
        itemNotExitArray=[NSMutableArray arrayWithArray:[userDefaults objectForKey:@"SCANSTOCKITEMNOTEXIST"]];
        
    }
    else{
        itemCodeArray=[NSMutableArray array ];
        itemNameArray=[NSMutableArray array ];
        itemWhereArray=[NSMutableArray array ];
        itemPriceArray=[NSMutableArray array ];
        itemUrlArray=[NSMutableArray array ];
        itemWeightArray=[NSMutableArray array ];
        
      
        itemNotExitArray=[NSMutableArray array ];
    }
    float totalCount=0.0f;
    
    _scanTotalCountLabel.text=[NSString stringWithFormat:@"共有%lu件产品",(unsigned long)itemPriceArray.count];
    for (int i=0; i<itemPriceArray.count; i++) {
        totalCount=totalCount+[[itemPriceArray objectAtIndex:i] floatValue];
    }
    _scanTotalMoneyLabel.text=[Global floatConvertPercentile:totalCount];

 [_stockTableView reloadData];
}
-(void)handleSingleTap
{
    _popViewContainer.hidden=YES;
    CGRect frame1=_popViewContainer.frame;
    frame1.size.height=1;
    [_popViewContainer setFrame:frame1];
}
-(void)initPopView
{
    _popViewContainer.hidden=YES;
    CGRect frame1=_popViewContainer.frame;
    frame1.size.height=1;
    [_popViewContainer setFrame:frame1];
    
    [_displayBtn addTarget:self action:@selector(popViewBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_allocateBtn addTarget:self action:@selector(popViewBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_arrivalBtn addTarget:self action:@selector(popViewBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_inventoryBtn addTarget:self action:@selector(popViewBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)initPopResultView
{
//    rightCodeArray=[NSMutableArray array];
//    inventoryRightCodeArray=[NSMutableArray array];
//
    
    rightCodeStr=@"";
    guideCodeStr=@"";
    inventoryRightCodeStr=@"";
    
    CGRect frame1=_popResultViewContainer.frame;
    frame1.origin.y=768;
    [_popResultViewContainer setFrame:frame1];
    
    [_popResultAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_popResultAlphaView addTarget:self action:@selector(popResultAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    
    [_guideBtn addTarget:self action:@selector(popResultRightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_popResultRightBtn addTarget:self action:@selector(popResultRightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_inventoryRightBtn addTarget:self action:@selector(inventoryRightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    _popResultTextView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _popResultTextView.layer.borderWidth= 1.0f;
    _popResultTextView.layer.cornerRadius=3;
    
    for (UIView *v in _popResultScrollView.subviews) {
        [v removeFromSuperview];
    }
    CGRect frame2=_popResultScrollView.frame;
    frame2.size.height=1;
    [_popResultScrollView setFrame:frame2];
    
    _popResultScrollView.hidden=YES;
    
    typeNameStr=@"";


}
-(void)popResultRightBtnClick:(UIButton *)sender
{
    if (scrollIsOpen) {
        _popResultScrollView.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            CGRect frame=_popResultScrollView.frame;
            frame.size.height=1;
            [_popResultScrollView setFrame:frame];
            
        } completion:^(BOOL finished){
            scrollIsOpen=NO;
        }];

    }
    else
    {
    _popResultScrollView.hidden=NO;
   
        scrollIsOpen=YES;
    [_popResultScrollView setBackgroundColor:[UIColor whiteColor]];
    for (UIView *v in _popResultScrollView.subviews) {
        [v removeFromSuperview];
    }
        typeNameStr=@"OTHER";
        if (sender.tag==1000) {
            typeNameStr=@"GUIDE";
            [ _popResultScrollView setFrame:CGRectMake(20,131, 580,577)];
            [self requestGuideList];
        }
        if (typeTag==100&&sender.tag==1001) {
             [ _popResultScrollView setFrame:CGRectMake(20,191, 580,637)];
            [self requestDisplay];
        }
        if (typeTag==101&&sender.tag==1001) {
            [ _popResultScrollView setFrame:CGRectMake(20,191, 580,637)];
            whereTypeStr=@"T";
            [self requestAllocateList];
        }
        if (typeTag==102&&sender.tag==1001) {
            [ _popResultScrollView setFrame:CGRectMake(20,191, 580,637)];
            [self requestDeliveryList];
        }
        if (typeTag==103&&sender.tag==1001) {
            [ _popResultScrollView setFrame:CGRectMake(20,191, 580,637)];
            [self requestStyleList];
        }

    
 }
    
}
-(void)inventoryRightBtnClick
{
    if (scrollIsOpen) {
        _popResultScrollView.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            CGRect frame=_popResultScrollView.frame;
            frame.size.height=1;
            [_popResultScrollView setFrame:frame];
            
        } completion:^(BOOL finished){
            scrollIsOpen=NO;
        }];
        
    }
    else
    {

    _popResultScrollView.hidden=NO;
    for (UIView *v in _popResultScrollView.subviews) {
            [v removeFromSuperview];
    }
    [ _popResultScrollView setFrame:CGRectMake(20,265, 580,503)];
    [_popResultScrollView setBackgroundColor:[UIColor whiteColor]];
    scrollIsOpen=YES;
    
    whereTypeStr=@"C";
    typeNameStr=@"INVENTORY";
    [self requestAllocateList];
    }

}
-(void)requestGuideList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"Guide/GuideList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                 // NSLog(@"eeeeeee====%@",severDataDict.dataDict) ;
                 NSMutableArray *mGuidesArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        
                        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
                        CGRect rect=button.frame;
                        rect.size.height=50;
                        rect.size.width=545;
                        rect.origin.x=0;
                        rect.origin.y=50*i;
                        button.frame=rect;
                        button.tag=3000+i;
                        [button setBackgroundColor:[UIColor clearColor]];
                        [button setTitle:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserName"] forState:UIControlStateNormal];
                        //   [inventoryRightCodeArray addObject:[[mStyleArray objectAtIndex:i] objectForKey:@"ItypeCode"]];
                        [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                        [button addTarget:self action:@selector(selectRightTextBtn:) forControlEvents:UIControlEventTouchUpInside];
                        
                        
                        UILabel *textLabel=[[UILabel alloc] initWithFrame:CGRectMake(25, 20, 400, 20)];
                        [textLabel setText:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserName"]];
                        [textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
                        [textLabel setBackgroundColor:[UIColor clearColor]];
                        [button addSubview:textLabel];
                        
                        
                        UILabel *codeLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
                        [codeLabel setBackgroundColor:[UIColor clearColor]];
                        [codeLabel setTextColor:[UIColor clearColor]];
                        codeLabel.tag=6000+i;
                        codeLabel.text=[[mGuidesArray objectAtIndex:i] objectForKey:@"UserCode"];
                        [_popResultScrollView addSubview:codeLabel];
                        
                        UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(10,49, 600, 1)];
                        // NSLog(@"lineLabel.origin.y ==%f",lineLabel.frame.origin.y);
                        [lineLabel setBackgroundColor:[UIColor clearColor]];
                        [lineLabel setText:@"－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－"];
                        [lineLabel setTextColor:[UIColor colorWithRed:241.0f/255.0f green:241.0f/255.0f blue:241.0f/255.0f alpha:1.0f]];
                        [button addSubview:lineLabel];
                        [_popResultScrollView addSubview:button];

                    }
                    [_popResultScrollView setContentSize:CGSizeMake(0, 50*mGuidesArray.count+10)];
                    [_popResultScrollView setShowsVerticalScrollIndicator:NO];
                    [_popResultScrollView setScrollEnabled:YES];
                   
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
//                    UIViewController *controller=[[GlobalViewController alloc]init];
//                    [self.navigationController pushViewController:controller animated:YES];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

-(void)requestStyleList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:@"CheckVouch" forKey:@"BType"];
        [HttpRequest requestData:@"StoreManager/GetMItypeList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                   
                  //  [inventoryRightCodeArray removeAllObjects];
                    NSMutableArray *mStyleArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<mStyleArray.count; i++) {
                        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
                        CGRect rect=button.frame;
                        rect.size.height=50;
                        rect.size.width=545;
                        rect.origin.x=0;
                        rect.origin.y=50*i;
                        button.frame=rect;
                        button.tag=3000+i;
                        [button setBackgroundColor:[UIColor clearColor]];
                        [button setTitle:[[mStyleArray objectAtIndex:i] objectForKey:@"ItypeName"] forState:UIControlStateNormal];
                     //   [inventoryRightCodeArray addObject:[[mStyleArray objectAtIndex:i] objectForKey:@"ItypeCode"]];
                        [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                        [button addTarget:self action:@selector(selectRightTextBtn:) forControlEvents:UIControlEventTouchUpInside];
                        
                        
                        UILabel *textLabel=[[UILabel alloc] initWithFrame:CGRectMake(25, 20, 400, 20)];
                        [textLabel setText:[[mStyleArray objectAtIndex:i] objectForKey:@"ItypeName"]];
                        [textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
                        [textLabel setBackgroundColor:[UIColor clearColor]];
                        [button addSubview:textLabel];
                        
                        
                        UILabel *codeLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
                        [codeLabel setBackgroundColor:[UIColor clearColor]];
                        [codeLabel setTextColor:[UIColor clearColor]];
                        codeLabel.tag=6000+i;
                        codeLabel.text=[[mStyleArray objectAtIndex:i] objectForKey:@"ItypeCode"];
                        [_popResultScrollView addSubview:codeLabel];

                        UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(10,49, 600, 1)];
                        // NSLog(@"lineLabel.origin.y ==%f",lineLabel.frame.origin.y);
                        [lineLabel setBackgroundColor:[UIColor clearColor]];
                        [lineLabel setText:@"－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－"];
                        [lineLabel setTextColor:[UIColor colorWithRed:241.0f/255.0f green:241.0f/255.0f blue:241.0f/255.0f alpha:1.0f]];
                        [button addSubview:lineLabel];
                        [_popResultScrollView addSubview:button];
                        
                    }
                   //  NSLog(@"3333===%@",inventoryRightCodeArray);
                    [_popResultScrollView setContentSize:CGSizeMake(0, 50*mStyleArray.count+10)];
                    [_popResultScrollView setShowsVerticalScrollIndicator:NO];
                    [_popResultScrollView setScrollEnabled:YES];
 
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                   
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                       [Global loginViewController:self noteStr:requestResultStr];
                      //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}
-(void)requestDisplay
{
    NSArray *array=[NSArray arrayWithObjects:@"上柜",@"下柜", nil];
    for (int i=0; i<array.count; i++) {
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        CGRect rect=button.frame;
        rect.size.height=50;
        rect.size.width=545;
        rect.origin.x=0;
        rect.origin.y=50*i;
        button.frame=rect;
        button.tag=3000+i;
        [button setBackgroundColor:[UIColor clearColor]];
        [button setTitle:[array objectAtIndex:i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
        
        if ([typeNameStr isEqualToString:@"OTHER"]) {
            [button addTarget:self action:@selector(selectRightTextBtn:) forControlEvents:UIControlEventTouchUpInside];
        }
        
//        else if ([typeNameStr isEqualToString:@"Y"])
//        {
//            [button addTarget:self action:@selector(selectInventoryRightTextBtn:) forControlEvents:UIControlEventTouchUpInside];
//        }
        
        
        UILabel *textLabel=[[UILabel alloc] initWithFrame:CGRectMake(25, 20, 400, 20)];
        [textLabel setText:[array objectAtIndex:i] ];
        [textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
        [textLabel setBackgroundColor:[UIColor clearColor]];
        [button addSubview:textLabel];
        
        UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(10,49, 600, 1)];
        // NSLog(@"lineLabel.origin.y ==%f",lineLabel.frame.origin.y);
        [lineLabel setBackgroundColor:[UIColor clearColor]];
        [lineLabel setText:@"－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－"];
        [lineLabel setTextColor:[UIColor colorWithRed:241.0f/255.0f green:241.0f/255.0f blue:241.0f/255.0f alpha:1.0f]];[button addSubview:lineLabel];
        [_popResultScrollView addSubview:button];
        
    }
    [_popResultScrollView setContentSize:CGSizeMake(0, 50*array.count+10)];
    [_popResultScrollView setShowsVerticalScrollIndicator:NO];
    [_popResultScrollView setScrollEnabled:YES];

}
-(void)requestAllocateList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:whereTypeStr forKey:@"WhsType"];
        [HttpRequest requestData:@"StoreManager/WhsList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                //    [rightCodeArray removeAllObjects];
                  //  NSLog(@"1111==%@",severDataDict.dataDict);
                  NSMutableArray * mAllocateArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<mAllocateArray.count; i++) {
                        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
                        CGRect rect=button.frame;
                        rect.size.height=50;
                        rect.size.width=545;
                        rect.origin.x=0;
                        rect.origin.y=50*i;
                        button.frame=rect;
                        button.tag=3000+i;
                        [button setBackgroundColor:[UIColor clearColor]];
                        [button setTitle:[[mAllocateArray objectAtIndex:i] objectForKey:@"WhsName"] forState:UIControlStateNormal];
                        
                      //  [rightCodeArray addObject:[[mAllocateArray objectAtIndex:i] objectForKey:@"WhsCode"]];
                        [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                        
                      
                        [button addTarget:self action:@selector(selectRightTextBtn:) forControlEvents:UIControlEventTouchUpInside];
                        
                        
                        UILabel *textLabel=[[UILabel alloc] initWithFrame:CGRectMake(25, 20, 400, 20)];
                        [textLabel setText:[[mAllocateArray objectAtIndex:i] objectForKey:@"WhsName"]];
                        [textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
                        [textLabel setBackgroundColor:[UIColor clearColor]];
                        [button addSubview:textLabel];
                        
                        UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(10,49, 600, 1)];
                        // NSLog(@"lineLabel.origin.y ==%f",lineLabel.frame.origin.y);
                        [lineLabel setBackgroundColor:[UIColor clearColor]];
                        [lineLabel setText:@"－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－"];
                        [lineLabel setTextColor:[UIColor colorWithRed:241.0f/255.0f green:241.0f/255.0f blue:241.0f/255.0f alpha:1.0f]];
                        [button addSubview:lineLabel];
                        
                        UILabel *codeLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
                        [codeLabel setBackgroundColor:[UIColor clearColor]];
                        [codeLabel setTextColor:[UIColor clearColor]];
                        codeLabel.tag=6000+i;
                        codeLabel.text=[[mAllocateArray objectAtIndex:i] objectForKey:@"WhsCode"];
                        [_popResultScrollView addSubview:codeLabel];
                        
                        [_popResultScrollView addSubview:button];

                    }
                    [_popResultScrollView setContentSize:CGSizeMake(0, 50*mAllocateArray.count+10)];
                    [_popResultScrollView setShowsVerticalScrollIndicator:NO];
                    [_popResultScrollView setScrollEnabled:YES];
                    
                    
                   // [_orderFilterMainView bringSubviewToFront:_orderFilterScrollView];
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                      [Global loginViewController:self noteStr:requestResultStr];
                     //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
-(void)requestDeliveryList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
     //   NSLog(@"params===%@",params);
        [HttpRequest requestData:@"StoreManager/DeliveryListIP" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                   // [rightCodeArray removeAllObjects];
                   //NSLog(@"1111==%@",severDataDict.dataDict);
                    NSMutableArray * mDeliverArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<mDeliverArray.count; i++) {
                        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
                        CGRect rect=button.frame;
                        rect.size.height=50;
                        rect.size.width=545;
                        rect.origin.x=0;
                        rect.origin.y=50*i;
                        button.frame=rect;
                        button.tag=3000+i;
                        [button setBackgroundColor:[UIColor clearColor]];
                        [button setTitle: [NSString stringWithFormat:@"%@",[[mDeliverArray objectAtIndex:i] objectForKey:@"DocNum"] ] forState:UIControlStateNormal];
                        
                       // [rightCodeArray addObject:[[mDeliverArray objectAtIndex:i] objectForKey:@"WhsCode"]];
                        [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                        
                        [button addTarget:self action:@selector(selectRightTextBtn:) forControlEvents:UIControlEventTouchUpInside];
                        
                        
                        UILabel *textLabel=[[UILabel alloc] initWithFrame:CGRectMake(32, 20, 400, 20)];
                         [textLabel setText:[NSString stringWithFormat:@"%@",[[mDeliverArray objectAtIndex:i] objectForKey:@"DocNum"]]];
                        [textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
                        [textLabel setBackgroundColor:[UIColor clearColor]];
                        [button addSubview:textLabel];
                        
                        UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(10,49, 555, 1)];
                        // NSLog(@"lineLabel.origin.y ==%f",lineLabel.frame.origin.y);
                        [lineLabel setBackgroundColor:[UIColor clearColor]];
                        [lineLabel setText:@"－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－"];
                        [lineLabel setTextColor:[UIColor colorWithRed:241.0f/255.0f green:241.0f/255.0f blue:241.0f/255.0f alpha:1.0f]];
                        [button addSubview:lineLabel];
                        
                        UILabel *codeLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
                        [codeLabel setBackgroundColor:[UIColor clearColor]];
                        [codeLabel setTextColor:[UIColor clearColor]];
                        codeLabel.tag=6000+i;
                        codeLabel.text=[NSString stringWithFormat:@"%d",[[[mDeliverArray objectAtIndex:i] objectForKey:@"DocEntry"] intValue]];
                        [_popResultScrollView addSubview:codeLabel];
                        
                        [_popResultScrollView addSubview:button];
                        
                    }
                    [_popResultScrollView setContentSize:CGSizeMake(0, 50*mDeliverArray.count+10)];
                    [_popResultScrollView setShowsVerticalScrollIndicator:NO];
                    [_popResultScrollView setScrollEnabled:YES];
                    
                    
                    // [_orderFilterMainView bringSubviewToFront:_orderFilterScrollView];
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                     [Global loginViewController:self noteStr:requestResultStr];
                      //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

-(void)selectRightTextBtn:(UIButton *)sender
{
    // NSLog(@"sender.titleLabel.text=====%@",sender.titleLabel.text);
    if ([typeNameStr isEqualToString:@"GUIDE"]) {
        _popResultViewGuideNameLabel.text=sender.titleLabel.text;
      
        [_popResultGuideRightImg setFrame: CGRectMake(545,8, 30, 30)];
        // [self resizeLabel1:_popResultViewGuideNameLabel];
        [Global resizeForLable:_popResultViewGuideNameLabel WithText:_popResultViewGuideNameLabel.text parentView:self.view];
        CGRect frameK=_popResultViewGuideNameLabel.frame;
        frameK.origin.x=_popResultGuideRightImg.frame.origin.x-frameK.size.width-5;
        _popResultViewGuideNameLabel.frame=frameK;

        for (UIView *v in _popResultScrollView.subviews) {
            
            if (v.tag==sender.tag+3000) {
                UILabel *label=(UILabel *)v;
                guideCodeStr=label.text;
                
            }
        }
     //   NSLog(@"guideCodeStr=====%@",guideCodeStr);
         [_popResultGuideRightImg setFrame: CGRectMake(_popResultViewGuideNameLabel.frame.origin.x+_popResultViewGuideNameLabel.frame.size.width+5,8, 30, 30)];
        
      //  [_popResultViewRightImg setFrame: CGRectMake(_popResultViewRightLabel.frame.origin.x+_popResultViewRightLabel.frame.size.width+5,8, 30, 30)];
    }
    
   else if ([typeNameStr isEqualToString:@"OTHER"]) {
         _popResultViewRightLabel.text=sender.titleLabel.text;
       
       [_popResultViewRightImg setFrame: CGRectMake(545,8, 30, 30)];
       
       [Global resizeForLable:_popResultViewRightLabel WithText:_popResultViewRightLabel.text parentView:self.view];
       CGRect frameK=_popResultViewRightLabel.frame;
       frameK.origin.x=_popResultViewRightImg.frame.origin.x-frameK.size.width-5;
       _popResultViewRightLabel.frame=frameK;

       
        for (UIView *v in _popResultScrollView.subviews) {
            
            if (v.tag==sender.tag+3000) {
                 UILabel *label=(UILabel *)v;
                rightCodeStr=label.text;
               
            }
        }
       
        
        [_popResultViewRightImg setFrame: CGRectMake(_popResultViewRightLabel.frame.origin.x+_popResultViewRightLabel.frame.size.width+5,8, 30, 30)];
    }
    else if([typeNameStr isEqualToString:@"INVENTORY"])
    {
        // NSLog(@"sender.titleLabel.text1111=====%@",sender.titleLabel.text);
        _inventoryRightLabel.text=sender.titleLabel.text;
         [_inventoryRightImg setFrame: CGRectMake(545,8, 30, 30)];
        [Global resizeForLable:_inventoryRightLabel WithText:_inventoryRightLabel.text parentView:self.view];
        CGRect frameK=_inventoryRightLabel.frame;
        frameK.origin.x=_inventoryRightImg.frame.origin.x-frameK.size.width-5;
        _inventoryRightLabel.frame=frameK;

        
        for (UIView *v in _popResultScrollView.subviews) {
            
            if (v.tag==sender.tag+3000) {
                UILabel *label=(UILabel *)v;
                inventoryRightCodeStr=label.text;
            }
        }
        

        
        [_inventoryRightImg setFrame: CGRectMake(_inventoryRightLabel.frame.origin.x+_inventoryRightLabel.frame.size.width+5,8, 30, 30)];
      //  inventoryRightCodeStr=[inventoryRightCodeArray objectAtIndex:(sender.tag-3000)];
        
    }
    [UIView animateWithDuration:0.1f animations:^
     {
         CGRect frame1=_popResultScrollView.frame;
         frame1.size.height=1;
         [_popResultScrollView setFrame:frame1];
     }completion:^(BOOL finished) {
         _popResultScrollView.hidden=YES;
         scrollIsOpen=NO;
         
     }];
   


}
-(void)selectInventoryRightTextBtn:(UIButton *)sender
{
    _inventoryRightLabel.text=sender.titleLabel.text;
    [UIView animateWithDuration:0.1f animations:^
     {
         CGRect frame1=_popResultScrollView.frame;
         frame1.size.height=1;
         [_popResultScrollView setFrame:frame1];
     }completion:^(BOOL finished) {
         _popResultScrollView.hidden=YES;
         scrollIsOpen=NO;
         
     }];
    [_inventoryRightImg setFrame: CGRectMake(545, 16, 30, 30)];
    
    [Global resizeForLable:_inventoryRightLabel WithText:_inventoryRightLabel.text parentView:self.view];
    CGRect frameK=_inventoryRightLabel.frame;
    frameK.origin.x=_inventoryRightImg.frame.origin.x-frameK.size.width-5;
    _inventoryRightLabel.frame=frameK;

}
-(void)popResultAlphaViewClick
{
    for (UIView *v in _popResultScrollView.subviews) {
        [v removeFromSuperview];
    }
    CGRect frame2=_popResultScrollView.frame;
    frame2.size.height=1;
    [_popResultScrollView setFrame:frame2];
    
    scrollIsOpen=NO;
    
    _popResultScrollView.hidden=YES;

    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect frame1=_popResultViewContainer.frame;
         frame1.origin.y=768;
         [_popResultViewContainer setFrame:frame1];
     }completion:^(BOOL finished) {
         
     }];

}
-(void)clearAllBtnClick
{
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"确定清空列表？" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    alert.tag=200;
    alert.delegate=self;
    [alert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    // the user clicked OK
    if (alertView.tag==200) {
       /// NSLog(@"0000000");
        if (buttonIndex == 0)
        {//NSLog(@"11111111");
            [itemCodeArray removeAllObjects];
            [itemNameArray removeAllObjects];
            [itemWhereArray removeAllObjects];
            [itemPriceArray removeAllObjects];
            [itemUrlArray removeAllObjects];
            [itemWeightArray removeAllObjects];
            
          
            [itemNotExitArray removeAllObjects];

            [_stockTableView reloadData];
            [self resetDefaults];
             _scanTotalCountLabel.text=[NSString stringWithFormat:@"共有0件产品"];
            _scanTotalMoneyLabel.text=@"";

        }
    }
}
- (void)resetDefaults {
    NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
    NSDictionary * dict = [defs dictionaryRepresentation];
    for (id key in dict) {
        if ([key isEqualToString:@"SCANSTOCKITEMCODE"]||[key isEqualToString:@"SCANSTOCKITEMNAME"]||[key isEqualToString:@"SCANSTOCKITEMWHERE"]||[key isEqualToString:@"SCANSTOCKITEMPRICE"]||[key isEqualToString:@"SCANSTOCKITEMURL"]||[key isEqualToString:@"SCANSTOCKITEMWEIGHT"]||[key isEqualToString:@"SCANSTOCKITEMSERIESNAME"]||[key isEqualToString:@"SCANSTOCKITEMTYPENAME"]||[key isEqualToString:@"SCANSTOCKITEMINDATE"]||[key isEqualToString:@"SCANSTOCKITEMNOTEXIST"]) {
            [defs removeObjectForKey:key];
        }
        
    }
    [defs synchronize];
}


-(void)popViewBtnClick:(UIButton *)sender
{
    CGRect frame=_popResultTextView.frame;
    frame.origin.y=300;
    _popResultTextView.frame=frame;
    
    _popResultViewRightLabel.text=@"";
     _inventoryRightLabel.text=@"";
    
    CGRect frame1=_popResultViewRightLabel.frame;
    frame1.origin.x=440;
    frame1.size.width=30;
    _popResultViewRightLabel.frame=frame1;
    
    CGRect frame2=_popResultViewRightImg.frame;
    frame2.origin.x=545;
    _popResultViewRightImg.frame=frame2;
    
    CGRect frame3=_inventoryRightLabel.frame;
    frame3.origin.x=440;
    frame3.size.width=30;
    _inventoryRightLabel.frame=frame1;
    
    CGRect frame4=_inventoryRightImg.frame;
    frame4.origin.x=545;
    _inventoryRightImg.frame=frame4;
    
    guideCodeStr=[Global getGuideCodeStr];
    _popResultViewGuideNameLabel.text=[Global getGuideNameStr];
    
    [_popResultGuideRightImg setFrame: CGRectMake(545,8, 30, 30)];
    //[self resizeLabel1:_popResultViewGuideNameLabel];
    [Global resizeForLable:_popResultViewGuideNameLabel WithText:_popResultViewGuideNameLabel.text parentView:self.view];
    CGRect frameK=_popResultViewGuideNameLabel.frame;
    frameK.origin.x=_popResultGuideRightImg.frame.origin.x-frameK.size.width-5;
    _popResultViewGuideNameLabel.frame=frameK;
    _popResultRightBtn.hidden=NO;
    if (sender.tag==100) {
        _popResultViewTitleLabel.text=@"陈列";
        _popResultViewLeftLabel.text=@"类型";
        _inventorySelectView.hidden=YES;
        
        typeTag=100;
        
    }
   else if (sender.tag==101) {
        _popResultViewTitleLabel.text=@"调拨";
       _popResultViewLeftLabel.text=@"调拨到";
       _inventorySelectView.hidden=YES;
        typeTag=101;
    }
   else if (sender.tag==102) {
        _popResultRightBtn.hidden=YES;
        _popResultViewTitleLabel.text=@"到货";
       _popResultViewLeftLabel.text=@"到货单";
       _inventorySelectView.hidden=YES;
        typeTag=102;
    }
   else if (sender.tag==103) {
        _popResultViewTitleLabel.text=@"盘点";
        _popResultViewLeftLabel.text=@"类别";
       _inventorySelectView.hidden=NO;
       CGRect frame=_popResultTextView.frame;
       frame.origin.y=300;
       _popResultTextView.frame=frame;
        typeTag=103;
    }
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect frame1=_popResultViewContainer.frame;
         frame1.origin.y=0;
         [_popResultViewContainer setFrame:frame1];
     }completion:^(BOOL finished) {
         
     }];

}
-(IBAction)confirmClick:(id)sender
{
    if (itemCodeArray.count>0) {
        
    
    _popViewContainer.hidden=NO;
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect frame1=_popViewContainer.frame;
          frame1.size.height=239;
         [_popViewContainer setFrame:frame1];
     }completion:^(BOOL finished) {
         
     }];
    }
    else
    {
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"列表为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
    }

}
-(IBAction)confirmSubmitClick:(id)sender
{
    if (typeTag==100) {
        [self submitDisplay];
    }
    else if (typeTag==101)
    {
        [self submitAllocate];
    }
    else if (typeTag==102)
    {
        [self submitArrival];
    }
    else if(typeTag==103)
    {
     [self submitInventory];
    }
        
}
-(void)submitDisplay
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:guideCodeStr forKey:@"GuideCode"];
        NSString *typeStr=@"";
        if ([_popResultViewRightLabel.text isEqualToString:@"上柜"]) {
            typeStr=@"U";
        }
        else
        {
             typeStr=@"D";
        }
        [params setObject:typeStr forKey:@"DocType"];
        [params setObject:_popResultTextView.text forKey:@"Remark"];
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<itemCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[itemCodeArray objectAtIndex:i] forKey:@"ItemCode"];
            [mDocumentLine addObject:dic];
            
        }
        [params setObject:mDocumentLine forKey:@"DataLine"];
       //  NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"StoreManager/Count" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    CGRect frame1=_popResultViewContainer.frame;
                    frame1.origin.y=768;
                    [_popResultViewContainer setFrame:frame1];
                    
                    [itemCodeArray removeAllObjects];
                    [itemNameArray removeAllObjects];
                    [itemWhereArray removeAllObjects];
                    [itemPriceArray removeAllObjects];
                    [itemUrlArray removeAllObjects];
                    [itemWeightArray removeAllObjects];
                    
    
                    [itemNotExitArray removeAllObjects];
                    
                    [_stockTableView reloadData];
                    [self resetDefaults];
                    
                    _popViewContainer.hidden=YES;
                    CGRect frame2=_popViewContainer.frame;
                    frame2.size.height=1;
                    [_popViewContainer setFrame:frame2];
                   rightCodeStr=@"";
                    guideCodeStr=@"";
                   inventoryRightCodeStr=@"";
                    
                    _scanTotalCountLabel.text=[NSString stringWithFormat:@"共有0件产品"];
                    _scanTotalMoneyLabel.text=@"";
                   
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                      [Global loginViewController:self noteStr:requestResultStr];
                      //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}
-(void)submitAllocate
{
    
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<itemCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[itemCodeArray objectAtIndex:i] forKey:@"ItemCode"];
            [mDocumentLine addObject:dic];
            
        }
       
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:guideCodeStr forKey:@"GuideCode"];
        [params setObject:rightCodeStr forKey:@"WhsCode"];
        [params setObject:_popResultTextView.text forKey:@"Remark"];
         [params setObject:mDocumentLine forKey:@"DataLine"];
        //   [params setObject:@"U" forKey:@"DocType"];
        
       // [params setObject:mDocumentLine forKey:@"DataLine"];
        
          //  NSLog(@"aaaaaaaaaa===%@",params);
        [HttpRequest requestData:@"StoreManager/AddTrans" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            // [Global hideProgressHUDInternal:self.view];
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    CGRect frame1=_popResultViewContainer.frame;
                    frame1.origin.y=768;
                    [_popResultViewContainer setFrame:frame1];
                    
                    [itemCodeArray removeAllObjects];
                    [itemNameArray removeAllObjects];
                    [itemWhereArray removeAllObjects];
                    [itemPriceArray removeAllObjects];
                    [itemUrlArray removeAllObjects];
                    [itemWeightArray removeAllObjects];
                    [itemNotExitArray removeAllObjects];
                    
                    [_stockTableView reloadData];
                    [self resetDefaults];
                    
                    _popViewContainer.hidden=YES;
                    CGRect frame2=_popViewContainer.frame;
                    frame2.size.height=1;
                    [_popViewContainer setFrame:frame2];
                    rightCodeStr=@"";
                    guideCodeStr=@"";
                    inventoryRightCodeStr=@"";
                    _scanTotalCountLabel.text=[NSString stringWithFormat:@"共有0件产品"];
                    _scanTotalMoneyLabel.text=@"";
                    
                   

                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    [Global loginViewController:self noteStr:requestResultStr];
                     //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}

-(void)submitArrival
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:guideCodeStr forKey:@"GuideCode"];
       // [params setObject:rightCodeStr forKey:@"DocEntry"];
        [params setObject:_popResultTextView.text forKey:@"Remark"];
        
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<itemCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[itemCodeArray objectAtIndex:i] forKey:@"ItemCode"];
            [mDocumentLine addObject:dic];
            
        }
        [params setObject:mDocumentLine forKey:@"DataLine"];
        // NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"StoreManager/AddDeliveryIP" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    CGRect frame1=_popResultViewContainer.frame;
                    frame1.origin.y=768;
                    [_popResultViewContainer setFrame:frame1];
                    
                    [itemCodeArray removeAllObjects];
                    [itemNameArray removeAllObjects];
                    [itemWhereArray removeAllObjects];
                    [itemPriceArray removeAllObjects];
                    [itemUrlArray removeAllObjects];
                    [itemWeightArray removeAllObjects];
                    [itemNotExitArray removeAllObjects];
                    
                    [_stockTableView reloadData];
                    [self resetDefaults];
                    
                    _popViewContainer.hidden=YES;
                    CGRect frame2=_popViewContainer.frame;
                    frame2.size.height=1;
                    [_popViewContainer setFrame:frame2];
                    rightCodeStr=@"";
                    guideCodeStr=@"";
                    inventoryRightCodeStr=@"";
                    _scanTotalCountLabel.text=[NSString stringWithFormat:@"共有0件产品"];
                    _scanTotalMoneyLabel.text=@"";
                 
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                      [Global loginViewController:self noteStr:requestResultStr];
                      //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}
-(void)submitInventory
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:guideCodeStr forKey:@"GuideCode"];
        [params setObject:rightCodeStr forKey:@"ITypeCode"];
        [params setObject:inventoryRightCodeStr forKey:@"WhsCode"];
        
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<itemCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[itemCodeArray objectAtIndex:i] forKey:@"ItemCode"];
            [mDocumentLine addObject:dic];
            
        }
        [params setObject:mDocumentLine forKey:@"DataLine"];
       //  NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"StoreManager/AddCheckVouchIP" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    CGRect frame1=_popResultViewContainer.frame;
                    frame1.origin.y=768;
                    [_popResultViewContainer setFrame:frame1];
                    
                    [itemCodeArray removeAllObjects];
                    [itemNameArray removeAllObjects];
                    [itemWhereArray removeAllObjects];
                    [itemPriceArray removeAllObjects];
                    [itemUrlArray removeAllObjects];
                    [itemWeightArray removeAllObjects];
                    

                    [itemNotExitArray removeAllObjects];
                    
                    [_stockTableView reloadData];
                    [self resetDefaults];

                    _popViewContainer.hidden=YES;
                    CGRect frame2=_popViewContainer.frame;
                    frame2.size.height=1;
                    [_popViewContainer setFrame:frame2];
                    rightCodeStr=@"";
                    guideCodeStr=@"";
                    inventoryRightCodeStr=@"";
                    _scanTotalCountLabel.text=[NSString stringWithFormat:@"共有0件产品"];
                    _scanTotalMoneyLabel.text=@"";
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                       [Global loginViewController:self noteStr:requestResultStr]; 
                     //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}
-(IBAction)scanStockBackClick
{
    if ([self.delegate respondsToSelector:@selector(scanStockBackClick)]) {
        
        [self.delegate scanStockBackClick];
    }

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
        
        return itemCodeArray.count;
   
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
        
        return 120;
   
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
        
        static NSString * const  leftIdentifier = @"leftIdentifier";
        ScanStockTableViewCell *cell=( ScanStockTableViewCell *)[tableView dequeueReusableCellWithIdentifier: leftIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ScanStockTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
        cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];
        //     NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:_selectID inSection:indexPath.section];
        //       // if (indexPath.row==0) {
        //            [tableView selectRowAtIndexPath:indexPath1 animated:NO scrollPosition:UITableViewScrollPositionNone];
        // }
        if (itemUrlArray.count>0) {
            if ([itemUrlArray objectAtIndex:indexPath.row]!=[NSNull null]&&[[itemUrlArray objectAtIndex:indexPath.row] length]>0) {
                [ cell.productImageView setImageWithURL:[NSURL URLWithString:[itemUrlArray objectAtIndex:indexPath.row]]];
            }
            else
            {
                [cell.productImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
            
        }
        if (itemNameArray.count>0) {
            if ([itemNameArray objectAtIndex:indexPath.row]!=[NSNull null]) {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@ %@",[itemCodeArray objectAtIndex:indexPath.row],[itemNameArray objectAtIndex:indexPath.row]];//[_itemNameArray objectAtIndex:indexPath.row];
            }
        }
        if (itemPriceArray.count>0) {
            if ([itemPriceArray objectAtIndex:indexPath.row]!=[NSNull null]) {
                cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",[Global floatConvertPercentile:[[itemPriceArray objectAtIndex:indexPath.row] floatValue]]];
            }
        }
            if(itemWhereArray.count>0)
        
            {
                cell.stockAddressLabel.text=[itemWhereArray objectAtIndex:indexPath.row];
            }
        if (itemWeightArray.count>0) {
            if ([itemWeightArray objectAtIndex:indexPath.row]!=[NSNull null]) {
                cell.weightLabel.text=[NSString stringWithFormat:@"%0.02fg",[[itemWeightArray objectAtIndex:indexPath.row] floatValue]];
            }
              [Global resizeForLable:cell.weightLabel WithText:cell.weightLabel.text parentView:self.view];
           // [self resizeLabel:cell.weightLabel];
            CGRect frame=cell.priceLabel.frame;
            frame.origin.x=cell.weightLabel.frame.origin.x+cell.weightLabel.frame.size.width+12;
            cell.priceLabel.frame=frame;
        }
        
        return cell;
    
   }
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_stockTableView) {
        return YES;
    }
    return NO;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_stockTableView) {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            
            [itemCodeArray removeObjectAtIndex:indexPath.row];
            [itemNameArray removeObjectAtIndex:indexPath.row];
            [itemWhereArray removeObjectAtIndex:indexPath.row];
            [itemPriceArray removeObjectAtIndex:indexPath.row];
            [itemUrlArray  removeObjectAtIndex:indexPath.row];
            [itemWeightArray removeObjectAtIndex:indexPath.row];
            
            // [tableView reloadData];
            [_stockTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            
            
            float totalCount=0.0f;
            for (int i=0; i<itemPriceArray.count; i++) {
                totalCount=totalCount+[[itemPriceArray objectAtIndex:i] floatValue];
            }
            _scanTotalMoneyLabel.text=[Global floatConvertPercentile:totalCount];
            
             _scanTotalCountLabel.text=[NSString stringWithFormat:@"共有%lu件产品",(unsigned long)itemPriceArray.count];
            
            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
            [userDefaults setObject:itemCodeArray forKey:@"SCANSTOCKITEMCODE"];
            [userDefaults setObject:itemNameArray forKey:@"SCANSTOCKITEMNAME"];
            [userDefaults setObject:itemWhereArray forKey:@"SCANSTOCKITEMWHERE"];
            [userDefaults setObject:itemPriceArray forKey:@"SCANSTOCKITEMPRICE"];
            [userDefaults setObject:itemUrlArray forKey:@"SCANSTOCKITEMURL"];
            [userDefaults setObject:itemWeightArray forKey:@"SCANSTOCKITEMWEIGHT"];
            [userDefaults setObject:itemNotExitArray forKey:@"SCANSTOCKITEMNOTEXIST"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            
            if (itemCodeArray.count==0) {
                [self resetDefaults];
            }
            
        }
    }
    
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"删除";
}
- (void)textViewDidChange:(UITextView *)textView
{
    if (textView==_popResultTextView) {
    
    if (textView.text.length == 0) {
        _popResultTextViewImg.hidden=NO;
        _popResultTextViewLabel.hidden=NO;
        
    }
    else
    {
        _popResultTextViewImg.hidden=YES;
        _popResultTextViewLabel.hidden=YES;
        
    }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
